home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / registries / cpuinfo.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  2.5 KB  |  86 lines

  1. #
  2. # This file is part of Checkbox.
  3. #
  4. # Copyright 2008 Canonical Ltd.
  5. #
  6. # Checkbox is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Checkbox is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. from checkbox.lib.cache import cache
  20. from checkbox.lib.conversion import string_to_type
  21.  
  22. from checkbox.properties import Path
  23. from checkbox.registries.data import DataRegistry
  24. from checkbox.registries.filename import FilenameRegistry
  25. from checkbox.registries.link import LinkRegistry
  26.  
  27.  
  28. class ProcessorRegistry(DataRegistry):
  29.     """Registry for processor information.
  30.  
  31.     Each item contained in this registry consists of the information
  32.     for a single processor in the /proc/cpuinfo file.
  33.     """
  34.  
  35.     def items(self):
  36.         items = []
  37.         for line in [l.strip() for l in self.split("\n")]:
  38.             (key, value) = line.split(":", 1)
  39.  
  40.             # Sanitize key so that it can be expressed as
  41.             # an attribute
  42.             key = key.strip()
  43.             key = key.replace(" ", "_")
  44.             key = key.lower()
  45.  
  46.             # Rename processor entry to name
  47.             if key == "processor":
  48.                 key = "name"
  49.  
  50.             # Express value as a list if it is flags
  51.             value = value.strip()
  52.             if key == "flags":
  53.                 value = value.split()
  54.             else:
  55.                 value = string_to_type(value)
  56.  
  57.             items.append((key, value))
  58.  
  59.         items.append(("processor", LinkRegistry(self)))
  60.  
  61.         return items
  62.  
  63.  
  64. class CpuinfoRegistry(FilenameRegistry):
  65.     """Registry for cpuinfo information.
  66.  
  67.     Each item contained in this registry consists of the processor number
  68.     as key and the corresponding processor registry as value.
  69.     """
  70.  
  71.     # Filename where cpuinfo is stored.
  72.     filename = Path(default="/proc/cpuinfo")
  73.  
  74.     @cache
  75.     def items(self):
  76.         items = []
  77.         for data in [d.strip() for d in self.split("\n\n") if d]:
  78.             key = len(items)
  79.             value = ProcessorRegistry(data)
  80.             items.append((key, value))
  81.  
  82.         return items
  83.  
  84.  
  85. factory = CpuinfoRegistry
  86.